package com.tuanzi.loan.business.service.sms.el;

import java.util.List;

import org.springframework.expression.PropertyAccessor;
import org.springframework.expression.spel.support.StandardEvaluationContext;

import com.google.common.collect.Lists;
import com.tuanzi.loan.business.service.sms.el.accessor.BaseInfoPropertyAccessor;
import com.tuanzi.loan.business.service.sms.el.accessor.EliminateActivityPropertyAccessor;
import com.tuanzi.loan.business.service.sms.el.accessor.EliminateBlackListPropertyAccessor;
import com.tuanzi.loan.business.service.sms.el.accessor.MatchRuleRootPropertyAccessor;
import com.tuanzi.loan.business.service.sms.el.evaluator.MatchRuleRootEvaluator;
import com.tuanzi.loan.core.util.SpringContextHolder;

public class MatchRuleEvaluationContextBuilderImpl implements EvaluationContextBuilder {

	@Override
	public StandardEvaluationContext buildEvaluationContext() {

		StandardEvaluationContext context = new StandardEvaluationContext();

		context.setRootObject(buildEvaluateRoot());
		context.setPropertyAccessors(buildPropertyAccessor());

		return context;
	}

	private EvaluateRoot buildEvaluateRoot() {
		return SpringContextHolder.getBean(MatchRuleRootEvaluator.class);
	}

	private List<PropertyAccessor> buildPropertyAccessor() {
		List<PropertyAccessor> propertyAccessors = Lists.newArrayList();
		propertyAccessors.add(SpringContextHolder.getBean(MatchRuleRootPropertyAccessor.class));
		propertyAccessors.add(SpringContextHolder.getBean(BaseInfoPropertyAccessor.class));
		propertyAccessors.add(SpringContextHolder.getBean(EliminateActivityPropertyAccessor.class));
		propertyAccessors.add(SpringContextHolder.getBean(EliminateBlackListPropertyAccessor.class));
		return propertyAccessors;
	}
}
